    var Lmanga;
    var Lranobe;
    var res;
    var len = 0;
    var mas = null;
    var nameTable = null;
    var list = null;  
    
    var names = ["manga","ranobe"]; 
    var marker = new Array(2);
    
    $(document).on('pagebeforeshow', '#options', function(){  
        setStyle("markers");
        $("#a_head_c").hide();
        
        setTimeout(manga,0);
        setTimeout(ranobe,500);
    });
    
    function tabClick(tab){
    	nameTable = tab;
    }
    
    //for get date from BD
    function manga(){
    	forDB('get_manga', 'manga');
    }
    
    function ranobe(){
    	forDB('get_ranobe', 'ranobe');
    }
    
    function forDB(name, li){
    	nameTable = name;
        list = li;
        var db = getBD();
        db.transaction(getValueFromDB, errorCB);
    }
    
    //get markers from bd
    function getValueFromDB(tx){
        tx.executeSql('SELECT * FROM '+nameTable, [], querySuccess, errorCB);
    }
    
    // Query the success callback of get markes
    function querySuccess(tx, results) {
        res = results;
        
        for (var i = 0; i<names.length; i++){
        	if (nameTable == ('get_'+names[i])){
        		marker[i] = res;
        		break;
        	}       	
        }       
        /*if (nameTable == 'get_manga'){
        	Lmanga = results;
        }else{
        	Lranobe = results;
        }	*/
        
        len = results.rows.length;
        
        if(len == 0)
            onBackKeyDown();
        
        $('#'+list).empty();
        for (var i=0; i<len; i++){
            $('#'+list).append(
                   '<li>' +
                        '<div class="div_style_update" id="' + list+i + '" onClick="liOnClick(this.id);">'+
                            results.rows.item(i).name +
                        '</div>'+
                    '</li>\n' 
                );
        }
        $('#'+list).listview('refresh');
        nameTable = 'get_manga';
    }
    
    // click on marker
    function liOnClick(id){
    	var buf;
    	
        for (var i = 0; i<names.length; i++){
        	if (nameTable == ('get_'+names[i])){
        		res = marker[i];
        		buf = id.replace(new RegExp(names[i],'g'),"");
        	}       	
        } 
    	
/*    	if (nameTable == "get_manga"){
    		res = Lmanga;
    		buf = id.replace(new RegExp("manga",'g'),"");

    	}else{
    		res = Lranobe;
    		buf = id.replace(new RegExp("ranobe",'g'),"");
    	}*/
        
        if ( $('#a_head_c').is(':hidden') ){
             window.location = "../records/type.html?"+res.rows.item(parseInt(buf)).data;
        }else{
            if(mas == null)
                return;
            if (mas[buf] == 0){
                $('#'+id).css('color','red');
                mas[buf] = 1;
            }else{
                $('#'+id).css('color','white');
                mas[buf] = 0;
            }
        }
    }   
    
    //click button in head
    function clearBD(){
        var r=confirm("Стереть все закладки?");
        if (r==true)
          {
            var db = getBD();
            db.transaction(cleanBD, errorCB, successCB);
          }
        
    }
    
    //in head click button for checking or delete
    function checked(){
        if ( $('#a_head_c').is(':hidden') ){
            $('#a_head_c').show();
            mas = new Array(parseInt(len));
            for (var i=0; i<len; i++){
                mas[i]=0;
            }
        }else{
            var db = getBD();
            db.transaction(delElem, errorCB, successCB);
        }     
    }
    
    //cancel checked element
    function hideCheck(){
        $('#a_head_c').hide();
        for (var i=0; i<len; i++){
        	var buf = nameTable.replace(new RegExp('get_','g'),"");
            $('#'+buf+i).css('color','white');
            mas[i] = 0;
        }
        mas = null;
    }
    
    //delete some element from bd
    function delElem(tx){
        if (mas == null){
        	console.log("mas  =null");
            return;
        }
        for (var i=0; i<len; i++){
            if (mas[i] == 1){
                tx.executeSql('DELETE FROM '+nameTable+' where '+nameTable+'.id='+res.rows.item(i).id);               
            }            
        }
        setTimeout(manga,0);
        setTimeout(ranobe,500);         	
        //location.reload();
    }

    //delete all markers from bd
    function cleanBD(tx){
        tx.executeSql('DROP TABLE IF EXISTS '+nameTable);
        location.reload();     
    }   